package com.canyou.config;

import com.canyou.notify.DingTalkNotifier;
import de.codecentric.boot.admin.server.config.AdminServerNotifierAutoConfiguration;
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 钉钉提醒 自动配置
 *
 * @author fy
 * @date 19/10/25 16:13
 */
@Configuration
@AutoConfigureAfter({MailSenderAutoConfiguration.class})
public class DingTalkNotifierAutoConfiguration {

    @Configuration
    @ConditionalOnProperty(prefix = "spring.boot.admin.notify.ding-talk", name = "access-token")
    @AutoConfigureBefore({AdminServerNotifierAutoConfiguration.NotifierTriggerConfiguration.class, AdminServerNotifierAutoConfiguration.CompositeNotifierConfiguration.class})
    public static class DingTalkNotifierConfiguration {
        @Bean
        @ConditionalOnMissingBean
        @ConfigurationProperties("spring.boot.admin.notify.ding-talk")
        public DingTalkNotifier dingTalkNotifier(InstanceRepository repository) {
            return new DingTalkNotifier(repository);
        }
    }

}
